# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     loginPage.py
   Description :
   Author :        ZhangYiLin
   date：          2020/12/07 17:39
-------------------------------------------------
   Change Activity:
                   2020/12/07 17:39
-------------------------------------------------
"""
from common.BasePage import BasePage
from common.ParseConFile import ParseConFile
from common.NewLoguru import global_log
from selenium.webdriver.common.by import By


class LoginPage(BasePage):

    do_conf = ParseConFile('TestCase/TestLogin', 'login')

    USERNAME = do_conf.get_locators_or_account('loginPage', 'username')
    PASSWORD = do_conf.get_locators_or_account('loginPage', 'password')
    LGBT = (By.XPATH, "/html/body/div/div[1]/form/div[2]/button/span")

    def login(self, username, password):
        global_log.info('开始登录: username: {}, password: {}'.format(username, password))
        self.open_url()
        self.input_username(username)
        self.input_password(password)
        self.click_login()
        return self.driver

    def input_username(self, username):
        """
        输入账号
        :param username:
        :return:
        """
        global_log.info("输入账号： " + username)
        self.clear(*self.USERNAME)
        self.send_keys(username, *self.USERNAME)

    def input_password(self, password):
        """
        输入密码
        :param password:
        :return:
        """
        global_log.info("输入密码: " + password )
        self.clear(*self.PASSWORD)
        self.send_keys(password, *self.PASSWORD)

    def click_login(self):
        """
        点击登录
        :return:
        """
        global_log.info('点击登录')
        self.click(*self.LGBT)

    def return_default_frame(self):
        """
        返回默认的frame
        :return:
        """
        global_log.info("返回默认的frame")
        return self.switch_to_default_frame()


if __name__ == '__main__':
    from selenium import webdriver

    driver = webdriver.Chrome()
    driver.get("https://yjgl.zolbon.com")
    login = LoginPage(driver)
    print(login.USERNAME)
